public class Solution {
    private int[] arr;
    private boolean[] visited = new boolean[50001];

    private boolean dfs(int i) {
        if (i < 0 || i >= arr.length) return false;
        if (arr[i] == 0) return true;
        else if (visited[i]) return false;
        visited[i] = true;
        return dfs(i - arr[i]) || dfs(i + arr[i]);
    }

    public boolean canReach(int[] arr, int start) {
        this.arr = arr;
        return dfs(start);
    }
}